/*
 * Singularity Engine
 * Copyright (C) 2010 Vyacheslav Vorobyov, All rights reserved.
 * See LICENSE for full license information.
 */
package org.singularity.bom;

/**
 * TODO Describe this entity!
 * @author vjache
 */
public abstract class Predicate extends BooleanOperator
{
	public static enum PredCode
	{
		EQ,
		NE,
		GR,
		LS,
		GE,
		LE,
		LIKE,
		NOTLIKE,
		IN,
		CUSTOM;
	}
	
	public static interface Visitor<TL,TR>
	{
		void onEquals(Equals<TL,TR> aPredicate);
		void onNotEquals(NotEquals<TL,TR> aPredicate);
		void onGreater(Greater<TL,TR> aPredicate);
		void onLess(Less<TL,TR> aPredicate);
		void onGreaterEqual(GreaterEqual<TL,TR> aPredicate);
		void onLessEqual(LessEqual<TL,TR> aPredicate);
		void onLike(Like<TL,TR> aPredicate);
		void onNotLike(NotLike<TL,TR> aPredicate);
		void onIn(In<TL,TR> aPredicate);
		void onCustomUnaryPredicate(UnaryPredicate<?> aPredicate);
	}

	private PredCode _predCode;

	/**
	 * @param aOperatorCode
	 */
	public Predicate(PredCode aPredicateCode)
	{
		super(OpCode.PREDICATE);
		_predCode = aPredicateCode;
	}
	
	public PredCode getPredicateCode()
	{
		return _predCode;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void visit(BooleanOperator.Visitor aVisitor)
	{
		if(aVisitor instanceof Predicate.Visitor)
			visitPredicate((Predicate.Visitor) aVisitor);
		else
			aVisitor.onPredicate(this);
	}

	@SuppressWarnings("unchecked")
	public abstract void visitPredicate(Predicate.Visitor aVisitor);
}
